package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class CartController {

    @Autowired
    private ProductFeignClient productFeignClient;

    //  查看购物车列表
    @GetMapping("cart.html")
    public String cartList(){

        //  返回购物车列表
        return "cart/index";
    }

    //  添加购物车：
    // window.location.href = 'http://cart.gmall.com/addCart.html?skuId=' + this.skuId + '&skuNum=' + this.skuNum
    @RequestMapping("addCart.html")
    public String addCart(HttpServletRequest request){

        // 获取传递过来的参数
        String skuId = request.getParameter("skuId");
        String skuNum = request.getParameter("skuNum");

        // 使用远程调用
        SkuInfo skuInfo = productFeignClient.getAttrValueList(Long.parseLong(skuId));

        request.setAttribute("skuInfo",skuInfo);
        request.setAttribute("skuNum",skuNum);

        return "cart/addCart";
    }

}
